<!DOCTYPE html>


<html lang="en">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    问题集 |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
      <canvas width="1777" height="841"
        style="position: fixed; left: 0px; top: 0px; z-index: 99999; pointer-events: none;"></canvas>
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-待处理问题"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  问题集
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2022/02/17/%E5%BE%85%E5%A4%84%E7%90%86%E9%97%AE%E9%A2%98/" class="article-date">
  <time datetime="2022-02-17T02:21:42.000Z" itemprop="datePublished">2022-02-17</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E9%97%AE%E9%A2%98%E9%9B%86/">问题集</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">2.8k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">13 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="Object-keys-amp-for…in-顺序"><a href="#Object-keys-amp-for…in-顺序" class="headerlink" title="Object.keys() &amp; for…in 顺序"></a><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/40601459">Object.keys() &amp; for…in 顺序</a></h2><blockquote>
<p><code>Object.keys</code>在内部会根据属性名<code>key</code>的类型进行不同的排序逻辑。分三种情况：</p>
</blockquote>
<ul>
<li>如果属性名的类型是<code>Number</code>，那么<code>Object.keys</code>返回值是按照<code>key</code>从小到大排序 <strong>‘1’也算是number</strong></li>
<li>如果属性名的类型是<code>String</code>，那么<code>Object.keys</code>返回值是按照属性被创建的时间升序排序。</li>
<li>如果属性名的类型是<code>Symbol</code>，那么逻辑同<code>String</code>相同</li>
</ul>
<h2 id="解构赋值"><a href="#解构赋值" class="headerlink" title="解构赋值"></a>解构赋值</h2><blockquote>
<p>可以取代 delete xxx</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">const</span> &#123; name,...rest &#125; = &#123; <span class="attr">name</span>:<span class="string">&#x27;z&#x27;</span>, <span class="attr">age</span>:<span class="number">10</span>, <span class="attr">sex</span>:<span class="string">&#x27;female&#x27;</span> &#125;</span><br><span class="line"><span class="comment">// name = &#x27;z&#x27; , rest = &#123; age:10, sex:&#x27;female&#x27; &#125;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> [ item,...rest ] = [ &#123; <span class="attr">first</span>:<span class="string">&#x27;a&#x27;</span> &#125;, <span class="number">23</span>, <span class="number">55</span> ]</span><br><span class="line"><span class="comment">// item = &#123; first:&#x27;a&#x27; &#125; , rest = [ 23, 55 ]</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="json简写"><a href="#json简写" class="headerlink" title="json简写"></a>json简写</h2><blockquote>
<p><code>key</code>和<code>value</code>名字一样的时候可以省略<code>value</code></p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">let</span> name = <span class="string">&#x27;zz&#x27;</span></span><br><span class="line"><span class="keyword">let</span> age = <span class="number">10</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> json = &#123; name, age, say()&#123; <span class="built_in">console</span>.log(<span class="string">&#x27;&#x27;</span>) &#125; &#125;</span><br><span class="line"><span class="comment">// =&gt; let json = &#123; name:name, age:age, say:function()&#123; console.log(&#x27;&#x27;) &#125;  &#125;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h2 id="JavaScript浮点数运算精度问题"><a href="#JavaScript浮点数运算精度问题" class="headerlink" title="JavaScript浮点数运算精度问题"></a>JavaScript浮点数运算精度问题</h2><h3 id="描述"><a href="#描述" class="headerlink" title="描述"></a>描述</h3><blockquote>
<p>一开始看到百度的部分解决方案是通过扩大N倍换为整数，但是亲测有问题。直接乘10的N次方部分数据还是会出现精度问题。</p>
</blockquote>
<h3 id="解决"><a href="#解决" class="headerlink" title="解决"></a>解决</h3><blockquote>
</blockquote>
<ol>
<li>我是通过先转换成字符串、然后去掉小数点转为整数  </li>
<li>两个数之间小数点位数进行比较、少的在乘10的n-m次方，运算后在除以10的Math.max(n,m)</li>
</ol>
<p><del>目前没发现bug、不确定是正确的方法</del></p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 浮点数运算</span></span><br><span class="line"><span class="comment"> * type: 1 加法,2 减法</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">floatAddOrMinus</span>(<span class="params"><span class="keyword">type</span>: <span class="built_in">number</span>, arg1: <span class="built_in">string</span>, arg2: <span class="built_in">string</span></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">let</span> len1 = <span class="number">0</span></span><br><span class="line">    <span class="keyword">let</span> len2 = <span class="number">0</span></span><br><span class="line">    <span class="keyword">let</span> m = <span class="number">0</span></span><br><span class="line">    <span class="keyword">let</span> item1 = <span class="number">0</span></span><br><span class="line">    <span class="keyword">let</span> item2 = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        len1 = arg1.split(<span class="string">&quot;.&quot;</span>)[<span class="number">1</span>].length;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">        len1 = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        len2 = arg2.split(<span class="string">&quot;.&quot;</span>)[<span class="number">1</span>].length;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">        len2 = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (len1 &gt; len2) &#123;</span><br><span class="line">        m = len1;</span><br><span class="line">        item1 = <span class="number">0</span>;</span><br><span class="line">        item2 = len1 - len2;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        m = len2;</span><br><span class="line">        item1 = len2 - len1;</span><br><span class="line">        item2 = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">type</span> === <span class="number">1</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> (</span><br><span class="line">            (<span class="built_in">Number</span>(arg1.replace(<span class="string">&quot;.&quot;</span>, <span class="string">&quot;&quot;</span>)) * <span class="number">10</span> ** item1 +</span><br><span class="line">                <span class="built_in">Number</span>(arg2.replace(<span class="string">&quot;.&quot;</span>, <span class="string">&quot;&quot;</span>)) * <span class="number">10</span> ** item2) /</span><br><span class="line">            <span class="number">10</span> ** m</span><br><span class="line">        );</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> (</span><br><span class="line">            (<span class="built_in">Number</span>(arg1.replace(<span class="string">&quot;.&quot;</span>, <span class="string">&quot;&quot;</span>)) * <span class="number">10</span> ** item1 -</span><br><span class="line">                <span class="built_in">Number</span>(arg2.replace(<span class="string">&quot;.&quot;</span>, <span class="string">&quot;&quot;</span>)) * <span class="number">10</span> ** item2) /</span><br><span class="line">            <span class="number">10</span> ** m</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="vue3中ref和其他属性绑定值重名导致绑定失效"><a href="#vue3中ref和其他属性绑定值重名导致绑定失效" class="headerlink" title="vue3中ref和其他属性绑定值重名导致绑定失效"></a>vue3中ref和其他属性绑定值重名导致绑定失效</h2><blockquote>
<p>群友遇到的问题、我一开始看着也没觉得哪里不对。感觉以后能用的上，先存着 。</p>
</blockquote>
<h3 id="描述-1"><a href="#描述-1" class="headerlink" title="描述"></a>描述</h3><blockquote>
<p>使用<code>element-plus</code> 中的 <code>el-form</code> 的时候，model绑定了<code>formData</code>,但是在页面上对表单进行操作的时候，数据绑定无效。</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">el-form</span> </span></span><br><span class="line"><span class="tag"> <span class="attr">ref</span>=<span class="string">&quot;formData&quot;</span> </span></span><br><span class="line"><span class="tag"> <span class="attr">:model</span>=<span class="string">&quot;formData&quot;</span> </span></span><br><span class="line"><span class="tag"> <span class="attr">:rules</span>=<span class="string">&quot;rule&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">el-row</span> <span class="attr">justify</span>=<span class="string">&quot;center&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">el-col</span> <span class="attr">:span</span>=<span class="string">&quot;12&quot;</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">label</span>=<span class="string">&quot;入库类型&quot;</span> <span class="attr">prop</span>=<span class="string">&quot;inOutType&quot;</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">el-select</span> <span class="attr">v-model</span>=<span class="string">&quot;formData.inOutType&quot;</span> <span class="attr">clearable</span>&gt;</span></span><br><span class="line">              <span class="tag">&lt;<span class="name">el-option</span> <span class="attr">label</span>=<span class="string">&quot;外购&quot;</span> <span class="attr">value</span>=<span class="string">&quot;外购&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">el-option</span>&gt;</span></span><br><span class="line">              <span class="tag">&lt;<span class="name">el-option</span> <span class="attr">label</span>=<span class="string">&quot;其他&quot;</span> <span class="attr">value</span>=<span class="string">&quot;其他&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">el-option</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">el-select</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">el-col</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">el-row</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">el-form</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// ...</span></span><br><span class="line">setup()&#123;</span><br><span class="line">    <span class="keyword">let</span> formData: IEmptyObject = reactive(&#123;</span><br><span class="line">      warningUseTime: <span class="number">0</span>,</span><br><span class="line">      typeName: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      categoryCode: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      categoryName: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      maintenanceCode: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      maintenanceName: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      model: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      attribute: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      unit: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      warningProductionQuantity: <span class="number">0</span></span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> &#123; formData &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// ...</span></span><br></pre></td></tr></table></figure>

<h3 id="错误原因"><a href="#错误原因" class="headerlink" title="错误原因"></a>错误原因</h3><blockquote>
<p><code>ref</code>绑定的内容和<code>model</code>绑定的内容重复了，vue3中<code>ref</code>绑定的内容也是通过在<code>setup</code>中定义变量进行获取。具体原因还没仔细看，估计是ref的优先级更高？</p>
</blockquote>
<h2 id="proxy多个路由代理"><a href="#proxy多个路由代理" class="headerlink" title="proxy多个路由代理"></a>proxy多个路由代理</h2><blockquote>
<p><span style='color:red'>重写失效、请求路径包含某个 代理名 代理失效。</span></p>
</blockquote>
<p>记下 还没解决</p>
<h2 id="哈希路由引起样式问题"><a href="#哈希路由引起样式问题" class="headerlink" title="哈希路由引起样式问题"></a>哈希路由引起样式问题</h2><blockquote>
<p>在一个页面引入了样式，并且添加了 <code>scoped</code> ,但是在进行页面跳转的时候，这些引入的样式会影响另一页面。刷新之后就好了</p>
</blockquote>
<p>初步猜测是因为路由用的<code>哈希模式</code>的原因</p>
<blockquote>
<p><code>hash</code> 值变化不会导致浏览器向服务器发出请求</p>
</blockquote>
<p>所以在第一个页面加载的样式，在跳转之后没有刷新，样式就一直会存在，因此影响到了页面的样式</p>
<h3 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h3><ul>
<li><code>emit</code>父子组件通讯，点击事件触发后、强制刷新</li>
<li>监听<code>hash</code>值的变化、变化之后、强制刷新</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">setup: <span class="function">() =&gt;</span> &#123;</span><br><span class="line">   <span class="keyword">const</span> route = useRoute();</span><br><span class="line">   watch(</span><br><span class="line">     () =&gt; route.path,</span><br><span class="line">     (to, <span class="keyword">from</span>) =&gt; &#123;</span><br><span class="line">       <span class="keyword">if</span> (<span class="keyword">from</span>.includes(<span class="string">&quot;papercss&quot;</span>) &amp;&amp; <span class="keyword">from</span> !== to) &#123;</span><br><span class="line">         location.reload();</span><br><span class="line">       &#125;</span><br><span class="line">     &#125;</span><br><span class="line">   );</span><br><span class="line"> &#125;</span><br><span class="line"> </span><br></pre></td></tr></table></figure>

<h2 id="el-date-picker限制时间选择范围"><a href="#el-date-picker限制时间选择范围" class="headerlink" title="el-date-picker限制时间选择范围"></a>el-date-picker限制时间选择范围</h2><blockquote>
<p>两个时间选择器、开始时间与结束时间的时间选择范围为<code>24h</code>，并且精确到<code>分</code> (<code>format=&quot;yyyy-MM-dd HH:mm&quot;</code>)</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 基本使用 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">prop</span>=<span class="string">&quot;beginDateStr&quot;</span> <span class="attr">label</span>=<span class="string">&quot;开始时间&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">el-date-picker</span></span></span><br><span class="line"><span class="tag">    <span class="attr">v-model</span>=<span class="string">&quot;formData.beginDateStr&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">type</span>=<span class="string">&quot;datetime&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">placeholder</span>=<span class="string">&quot;选择日期时间&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">format</span>=<span class="string">&quot;yyyy-MM-dd HH:mm&quot;</span></span></span><br><span class="line"><span class="tag">  &gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">el-date-picker</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">prop</span>=<span class="string">&quot;endDateStr&quot;</span> <span class="attr">label</span>=<span class="string">&quot;结束时间&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">el-date-picker</span></span></span><br><span class="line"><span class="tag">    <span class="attr">v-model</span>=<span class="string">&quot;formData.endDateStr&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">type</span>=<span class="string">&quot;datetime&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">format</span>=<span class="string">&quot;yyyy-MM-dd HH:mm&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">placeholder</span>=<span class="string">&quot;选择日期时间&quot;</span></span></span><br><span class="line"><span class="tag">  &gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">el-date-picker</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="Picker-Options-配置"><a href="#Picker-Options-配置" class="headerlink" title="Picker Options 配置"></a>Picker Options 配置</h3><h4 id="开始时间限制"><a href="#开始时间限制" class="headerlink" title="开始时间限制"></a>开始时间限制</h4><blockquote>
<p>首先对开始时间进行限制 限制在当前日期之前；并且当开始日期改变的时候，结束日期清空</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://element.eleme.cn/#/zh-CN/component/datetime-picker">disabledDate 日期禁用范围</a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">el-date-picker</span></span></span><br><span class="line"><span class="tag">  <span class="attr">v-model</span>=<span class="string">&quot;formData.beginDateStr&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">type</span>=<span class="string">&quot;datetime&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">placeholder</span>=<span class="string">&quot;选择日期时间&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">format</span>=<span class="string">&quot;yyyy-MM-dd HH:mm&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">:picker-options</span>=<span class="string">&quot;pickerOptionsStart&quot;</span></span></span><br><span class="line"><span class="tag">  @<span class="attr">change</span>=<span class="string">&quot;handleChangeStart&quot;</span></span></span><br><span class="line"><span class="tag">&gt;</span><span class="tag">&lt;/<span class="name">el-date-picker</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> pickerOptionsStart = &#123;</span><br><span class="line">    disabledDate: <span class="function">(<span class="params">time: <span class="built_in">Date</span></span>) =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> time.getTime() &gt; <span class="built_in">Date</span>.now();</span><br><span class="line">    &#125;,</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> handleChangeStart() &#123;</span><br><span class="line">    <span class="built_in">this</span>.formData.endDateStr = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="结束时间限制"><a href="#结束时间限制" class="headerlink" title="结束时间限制"></a>结束时间限制</h4><blockquote>
<p>因为是24h限制、所以 开始时间+24h 和 开始时间-24h 的时间都得禁用；精确到分钟，小时和分钟也得进行限制</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://element.eleme.cn/#/zh-CN/component/time-picker">selectableRange 时间选择范围</a><br>这个属性没有在<code>el-date-picker</code>里面，在<code>el-time-picker</code>里面，个人觉得文档写的不是很人性…<br>因为跨天的话、时间范围是不一样的 比如开始时间是<code>2021-05-31 02:00</code><br>那么结束时间的范围是<code>2021-05-31 02:00 - 2021-06-01 02:00</code><br>如果选的是31号 则 <code>selectableRange = &#39;02:00-23:59&#39;</code><br>如果选的是1号 则 <code>selectableRange = &#39;00:00-02:00&#39;</code><br>所以还得对日期选择进行监听，本来是想通过点击/change事件进行监听的<br>但是无效，然后通过监听<code>input</code>框内数据的变化 来进行监听</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">el-date-picker</span></span></span><br><span class="line"><span class="tag">  <span class="attr">v-model</span>=<span class="string">&quot;formData.endDateStr&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">type</span>=<span class="string">&quot;datetime&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">format</span>=<span class="string">&quot;yyyy-MM-dd HH:mm&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">placeholder</span>=<span class="string">&quot;选择日期时间&quot;</span></span></span><br><span class="line"><span class="tag">  @<span class="attr">input</span>=<span class="string">&quot;handleChangeInputDate($event)&quot;</span></span></span><br><span class="line"><span class="tag">  <span class="attr">:picker-options</span>=<span class="string">&quot;&#123;</span></span></span><br><span class="line"><span class="tag"><span class="string">   disabledDate: (time) =&gt; hanldeDisabledDate(time),</span></span></span><br><span class="line"><span class="tag"><span class="string">    selectableRange: dafaulttime,</span></span></span><br><span class="line"><span class="tag"><span class="string">  &#125;&quot;</span></span></span><br><span class="line"><span class="tag">&gt;</span><span class="tag">&lt;/<span class="name">el-date-picker</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> dafaulttime: <span class="built_in">string</span> = <span class="string">&#x27;00:00:00-23:59:59&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> handleChangeInputDate(e: <span class="built_in">Date</span>) &#123;</span><br><span class="line">    <span class="comment">// 区别 同一天和下一天的时间限制</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">this</span>.formData.beginDateStr) &#123;</span><br><span class="line">      <span class="keyword">const</span> begin = <span class="keyword">new</span> EasyDate(<span class="built_in">this</span>.formData.beginDateStr).format(<span class="string">&#x27;dd&#x27;</span>);</span><br><span class="line">      <span class="keyword">const</span> end = <span class="keyword">new</span> EasyDate(e).format(<span class="string">&#x27;dd&#x27;</span>);</span><br><span class="line">      <span class="keyword">if</span> (begin === end) &#123;</span><br><span class="line">        <span class="built_in">this</span>.dafaulttime =</span><br><span class="line">          <span class="keyword">new</span> EasyDate(<span class="built_in">this</span>.formData.beginDateStr).format(<span class="string">&#x27;HH:mm:ss&#x27;</span>) +</span><br><span class="line">          <span class="string">&#x27;-23:59:59&#x27;</span>;</span><br><span class="line">      &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.dafaulttime =</span><br><span class="line">          <span class="string">&#x27;00:00:00-&#x27;</span> +</span><br><span class="line">          <span class="keyword">new</span> EasyDate(<span class="built_in">this</span>.formData.beginDateStr).format(<span class="string">&#x27;HH:mm:ss&#x27;</span>);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">private</span> hanldeDisabledDate(time: <span class="built_in">Date</span>) &#123;</span><br><span class="line">    <span class="comment">// 24 * 3600 * 1000 == 8.64e7</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">this</span>.formData.beginDateStr) &#123;</span><br><span class="line">      <span class="keyword">const</span> pickerMinDate = <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="built_in">this</span>.formData.beginDateStr).getTime();</span><br><span class="line">      <span class="keyword">const</span> maxTime = pickerMinDate + <span class="number">8.64e7</span>;</span><br><span class="line">      <span class="keyword">const</span> minTime = pickerMinDate - <span class="number">8.64e7</span>;</span><br><span class="line">      <span class="keyword">return</span> time.getTime() &gt;= maxTime || time.getTime() &lt;= minTime;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> time.getTime() &gt; <span class="built_in">Date</span>.now();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<h4 id="针对daterange和datetimerange类型进行时间限制"><a href="#针对daterange和datetimerange类型进行时间限制" class="headerlink" title="针对daterange和datetimerange类型进行时间限制"></a>针对<code>daterange</code>和<code>datetimerange</code>类型进行时间限制</h4><blockquote>
<p>不仅仅需要配置<code>disabledDate</code>，还需要配置<code>onPick</code>获取当前点击的日期<br>onPick  Function({ maxDate, minDate }) 选中日期执行的回调，只选择一个的时候返回的minDate</p>
</blockquote>
<p>实例：只能选择31天的范围</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">span</span>&gt;</span>起止时间：<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">el-date-picker</span></span></span><br><span class="line"><span class="tag">          <span class="attr">style</span>=<span class="string">&quot;width: 240px; margin-right: 10px&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">v-model</span>=<span class="string">&quot;dateRange&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">type</span>=<span class="string">&quot;datetimerange&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">range-separator</span>=<span class="string">&quot;至&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">value-format</span>=<span class="string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">start-placeholder</span>=<span class="string">&quot;开始日期&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">end-placeholder</span>=<span class="string">&quot;结束日期&quot;</span></span></span><br><span class="line"><span class="tag">          @<span class="attr">change</span>=<span class="string">&quot;dateChange&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">:picker-options</span>=<span class="string">&quot;&#123;</span></span></span><br><span class="line"><span class="tag"><span class="string">            disabledDate: (time) =&gt; hanldeDisabledDate(time),</span></span></span><br><span class="line"><span class="tag"><span class="string">            onPick: (time) =&gt; hanldeOnPick(time),</span></span></span><br><span class="line"><span class="tag"><span class="string">          &#125;&quot;</span></span></span><br><span class="line"><span class="tag">          <span class="attr">:clearable</span>=<span class="string">&quot;false&quot;</span></span></span><br><span class="line"><span class="tag">        &gt;</span><span class="tag">&lt;/<span class="name">el-date-picker</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">private</span> hanldeOnPick(e: IEmptyObject) &#123;</span><br><span class="line">  <span class="keyword">if</span> (!e.maxDate) &#123;</span><br><span class="line">    <span class="keyword">const</span> timeRange = <span class="number">8.64e7</span> * <span class="number">31</span>;</span><br><span class="line">    <span class="built_in">this</span>.pickDateRange.maxTime = e.minDate.getTime() + timeRange;</span><br><span class="line">    <span class="built_in">this</span>.pickDateRange.minTime = e.minDate.getTime() - timeRange;</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="built_in">this</span>.pickDateRange.minTime = <span class="literal">null</span>;</span><br><span class="line">    <span class="built_in">this</span>.pickDateRange.maxTime = <span class="literal">null</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> hanldeDisabledDate(e: <span class="built_in">Date</span>) &#123;</span><br><span class="line">  <span class="keyword">const</span> pickerDate = e.getTime();</span><br><span class="line">  <span class="keyword">if</span> (<span class="built_in">this</span>.pickDateRange.minTime &amp;&amp; <span class="built_in">this</span>.pickDateRange.maxTime) &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">      e.getTime() &lt;= <span class="built_in">this</span>.pickDateRange.minTime ||</span><br><span class="line">      e.getTime() &gt;= <span class="built_in">Date</span>.now() ||</span><br><span class="line">      e.getTime() &gt;= <span class="built_in">this</span>.pickDateRange.maxTime</span><br><span class="line">    );</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> e.getTime() &gt;= <span class="built_in">Date</span>.now();</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="主要问题"><a href="#主要问题" class="headerlink" title="主要问题"></a>主要问题</h3><blockquote>
<p>结束时间的 <code>picker-options</code> 属性,如果直接通过一个对象传递的话 ，会失效..,不清楚原因。我猜测是双向数据绑定相关的东西的问题</p>
</blockquote>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// √ 生效</span></span><br><span class="line">:picker-options=<span class="string">&quot;&#123;</span></span><br><span class="line"><span class="string">   disabledDate: (time) =&gt; hanldeDisabledDate(time),</span></span><br><span class="line"><span class="string">    selectableRange: dafaulttime,</span></span><br><span class="line"><span class="string">  &#125;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// × 不生效</span></span><br><span class="line">:picker-options=<span class="string">&quot;pickerOption&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> pickerOption = &#123;</span><br><span class="line">   disabledDate: <span class="function">(<span class="params">time</span>) =&gt;</span> hanldeDisabledDate(time),</span><br><span class="line">    selectableRange: dafaulttime,</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<h2 id="multipart-form-data-文件流请求和参数相关"><a href="#multipart-form-data-文件流请求和参数相关" class="headerlink" title="multipart/form-data 文件流请求和参数相关"></a>multipart/form-data 文件流请求和参数相关</h2><blockquote>
<p>一般的接口请求都是以json的形式进行传输、这次的表单会有文件上传的情况 所以用formdata的形式进行传输。</p>
</blockquote>
<p><code>表单数据存在body内 且content-type需要设置为application/json，文件数据存在file内</code><br><img src="https://i.bmp.ovh/imgs/2022/02/5db690ad15e1531e.png"></p>
<ol>
<li>formData请求，参数必须为<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/API/FormData">FromData</a>类型的</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> params = <span class="keyword">new</span> FormData()</span><br><span class="line"></span><br><span class="line">params.append(<span class="string">&#x27;file&#x27;</span>,value,name)</span><br><span class="line"></span><br><span class="line"><span class="comment">// params.get(&#x27;file&#x27;) 获取file值</span></span><br><span class="line"><span class="comment">// params.set(&#x27;file&#x27;,newValue) 设置file值</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>对于不是文本/二进制类型的数据，还需要使用<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/API/Blob">Blob对象</a>进行转换</li>
</ol>
<blockquote>
<p>如上图所示，<code>body</code>内传递的是<code>Object</code>对象，而且，<code>body</code>的<code>content-type</code>需要设置为<code>application/json</code>类型</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj = &#123;...&#125;</span><br><span class="line"><span class="keyword">let</span> blob = <span class="keyword">new</span> Blob([<span class="built_in">JSON</span>.stringify(obj)],&#123;<span class="attr">type</span>:<span class="string">&#x27;application/json&#x27;</span>&#125;)</span><br><span class="line"></span><br><span class="line">params.append(<span class="string">&#x27;body&#x27;</span>,blob)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="3">
<li>axios主要配置</li>
</ol>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// http.ts</span></span><br><span class="line"><span class="keyword">const</span> instance = axios.create(&#123;</span><br><span class="line">  timeout: <span class="number">600000</span>, <span class="comment">// by huangrong</span></span><br><span class="line">  headers: &#123; <span class="string">&#x27;Content-Type&#x27;</span>: <span class="string">&#x27;application/json&#x27;</span> &#125;,</span><br><span class="line">  baseURL: <span class="string">&#x27;/&#x27;</span>,</span><br><span class="line">  <span class="comment">// transformResponse: (data: any) =&gt; &#123;</span></span><br><span class="line">  <span class="comment">//   //</span></span><br><span class="line">  <span class="comment">// &#125;</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">instance.upload = <span class="function">(<span class="params">url, data, config = &#123;&#125;, params</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">const</span> formData = <span class="keyword">new</span> FormData();</span><br><span class="line">  data.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">    formData.append(<span class="string">&#x27;file&#x27;</span>, item.value, item.name || item.filename);</span><br><span class="line">  &#125;);</span><br><span class="line">  <span class="keyword">if</span> (params &amp;&amp; <span class="built_in">Object</span>.keys(params).length &gt; <span class="number">0</span>) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">const</span> m <span class="keyword">in</span> params) &#123;</span><br><span class="line">      <span class="keyword">if</span> (params.hasOwnProperty(m)) &#123;</span><br><span class="line">        <span class="keyword">const</span> key = m;</span><br><span class="line">        <span class="keyword">const</span> value = params[m];</span><br><span class="line">        formData.append(key, value);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> instance.request(&#123;</span><br><span class="line">    method: <span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">    ...config,</span><br><span class="line">    url,</span><br><span class="line">    data: formData,</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 请求拦截器</span></span><br><span class="line">instance.interceptors.request.use(<span class="function"><span class="params">config</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> &#123; params = &#123;&#125; &#125; = config;</span><br><span class="line">    config.params = &#123; ...params, time: <span class="keyword">new</span> <span class="built_in">Date</span>().getTime() &#125;;</span><br><span class="line">    <span class="comment">// add token if need</span></span><br><span class="line">    config.headers = &#123;</span><br><span class="line">      ...(config.headers || &#123;&#125;),</span><br><span class="line">      <span class="string">&#x27;X-Auth-Token&#x27;</span>: CookieStorage.token,</span><br><span class="line">      <span class="string">&#x27;X-Stargate-AppId&#x27;</span>: <span class="number">25</span>,</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="keyword">return</span> config;</span><br><span class="line">  &#125;, <span class="function"><span class="params">err</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// show err</span></span><br><span class="line">  &#125;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="comment">// common-api.ts</span></span><br><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">uploadFile</span>(<span class="params">path: <span class="built_in">string</span>, file: IUploadParam[], config?: AxiosRequestConfig, params?: IEmptyObject</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> http.upload(path, file, config, params).then(<span class="function"><span class="params">res</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Promise</span>.resolve(res.data);</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// index.vue</span></span><br><span class="line"> uploadFile(</span><br><span class="line">        <span class="built_in">this</span>.path,</span><br><span class="line">        (<span class="built_in">this</span>.$refs.imageUpload <span class="keyword">as</span> <span class="built_in">any</span>).fileList,</span><br><span class="line">        &#123;&#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          body: <span class="keyword">new</span> Blob(</span><br><span class="line">            [</span><br><span class="line">              <span class="built_in">JSON</span>.stringify(&#123;</span><br><span class="line">                ...this.formData,</span><br><span class="line">                factory: <span class="built_in">this</span>.factory,</span><br><span class="line">                workshop: <span class="built_in">this</span>.workshop,</span><br><span class="line">              &#125;),</span><br><span class="line">            ],</span><br><span class="line">            &#123; <span class="keyword">type</span>: <span class="string">&#x27;application/json&#x27;</span> &#125;</span><br><span class="line">          ),</span><br><span class="line">        &#125;</span><br><span class="line">      )</span><br></pre></td></tr></table></figure>

<h2 id="axios实现文件导出功能，无法获取response的异常信息"><a href="#axios实现文件导出功能，无法获取response的异常信息" class="headerlink" title="axios实现文件导出功能，无法获取response的异常信息"></a>axios实现文件导出功能，无法获取response的异常信息</h2><p><img src="https://i.bmp.ovh/imgs/2022/02/d7a045921c6cb54e.png"></p>
<p>如图所示: 上方是调文件导出接口，返回的异常信息。下方是普通请求获取的异常信息。上方的<code>data</code>内没有<code>errorMsg</code></p>
<h3 id="错误原因-1"><a href="#错误原因-1" class="headerlink" title="错误原因"></a>错误原因</h3><blockquote>
<p>可以看到上方红圈内的<code>data</code>是<code>Blob</code>类型的（文件存储类型），所以不能直接获取，需要<a href="!https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader"><code>FileReader</code></a>对象进行处理，转换获取blob、file文件的数据。</p>
</blockquote>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 响应拦截器</span></span><br><span class="line">instance.interceptors.response.use(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Promise</span>.resolve(response);</span><br><span class="line">&#125;, <span class="function"><span class="params">error</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// show error_msg and reject</span></span><br><span class="line">  <span class="comment">// console.log(&#x27;响应失败信息&#x27;, error.response);</span></span><br><span class="line">  <span class="keyword">if</span> (error &amp;&amp; error.response &amp;&amp; error.response.status) &#123;</span><br><span class="line">    <span class="keyword">let</span> errCode = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">let</span> errMsg = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">    <span class="keyword">if</span> (!!error.response.data) &#123;</span><br><span class="line">      <span class="comment">// 文件流错误处理</span></span><br><span class="line">      <span class="keyword">if</span> (error.response.config.responseType === <span class="string">&#x27;blob&#x27;</span>) &#123;</span><br><span class="line">        <span class="keyword">const</span> reader = <span class="keyword">new</span> FileReader();</span><br><span class="line">        reader.readAsText(error.response.data);</span><br><span class="line">        reader.onload = <span class="function">() =&gt;</span> &#123;</span><br><span class="line">          <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> &#123; errorMsg &#125; = <span class="built_in">JSON</span>.parse(reader.result <span class="keyword">as</span> <span class="built_in">string</span>);</span><br><span class="line">            errMsg = errorMsg;</span><br><span class="line">            handleError(error.response.status, errMsg);</span><br><span class="line">          &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="string">&#x27;解析错误&#x27;</span>);</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">      &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// 普通错误处理</span></span><br><span class="line">        <span class="keyword">const</span> &#123; status, errorMsg &#125; = error.response.data;</span><br><span class="line">        errCode = status;</span><br><span class="line">        errMsg = errorMsg;</span><br><span class="line">        handleError(error.response.status, errMsg);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Promise</span>.reject(error);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2022/02/17/%E5%BE%85%E5%A4%84%E7%90%86%E9%97%AE%E9%A2%98/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2022/03/08/JEPaaS/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            JEPaaS
          
        </div>
      </a>
    
    
      <a href="/2021/11/15/uniapp/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">uni-app</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "9OLyDF6ymKbs1woL9kh2qbae-gzGzoHsz",
    app_key: "RTkmORaJHqkGjEovHixLK04x",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2023
        <i class="ri-heart-fill heart_icon"></i> John Doe
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/avatar.webp" alt="Doreen&#39;s Blog"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->


<script src="/js/clickBoom2.js"></script>


<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


<script src="/js/dz.js"></script>



    
  </div>
</body>

</html>